package com.company.project.web;
import com.company.project.core.Result;
import com.company.project.core.ResultGenerator;
import com.company.project.model.ThesisAssessmentResult;
import com.company.project.service.ThesisAssessmentResultService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

import javax.annotation.Resource;
import java.util.List;

/**
* Created by CodeGenerator on 2018/10/08.
*/
@RestController
@RequestMapping("/thesis/assessment/result")
public class ThesisAssessmentResultController {
    @Resource
    private ThesisAssessmentResultService thesisAssessmentResultService;

    @PostMapping("/add")
    public Result add(ThesisAssessmentResult thesisAssessmentResult) {
        thesisAssessmentResultService.save(thesisAssessmentResult);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/delete")
    public Result delete(@RequestParam Integer id) {
        thesisAssessmentResultService.deleteById(id);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/update")
    public Result update(ThesisAssessmentResult thesisAssessmentResult) {
        thesisAssessmentResultService.update(thesisAssessmentResult);
        return ResultGenerator.genSuccessResult();
    }

    @PostMapping("/detail")
    public Result detail(@RequestParam Integer id) {
        ThesisAssessmentResult thesisAssessmentResult = thesisAssessmentResultService.findById(id);
        return ResultGenerator.genSuccessResult(thesisAssessmentResult);
    }

    @PostMapping("/list")
    public Result list(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer size) {
        PageHelper.startPage(page, size);
        List<ThesisAssessmentResult> list = thesisAssessmentResultService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }

    @GetMapping("/select/{thesisAssessmentId}")
    @ResponseBody
    public Result listByThesis(@PathVariable("thesisAssessmentId")Integer thesisAssessmentId) {
        List<ThesisAssessmentResult> list = thesisAssessmentResultService.getThesisAssessmentResultByThesisId(thesisAssessmentId);
        return ResultGenerator.genSuccessResult(list);
    }
}
